package com.tsinghuabigdata.edu.ddmath.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;

import com.tsinghuabigdata.edu.ddmath.R;
import com.tsinghuabigdata.edu.ddmath.bean.MonthSumbitedItem;
import com.tsinghuabigdata.edu.ddmath.bean.SubmitQuestion;
import com.tsinghuabigdata.edu.ddmath.module.ddwork.DDUploadActivity;
import com.tsinghuabigdata.edu.ddmath.module.ddwork.DDWorkListActivity;
import com.tsinghuabigdata.edu.ddmath.module.onlineTutoring.bean.ImagesBean;
import com.tsinghuabigdata.edu.ddmath.view.MultiGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * 已提交机构作业——适配器
 * Created by Administrator on 2017/2/17.
 */

public class SubmitedAgencyWorkAdatper extends CommonAdapter<MonthSumbitedItem> {

    public SubmitedAgencyWorkAdatper(Context context, List<MonthSumbitedItem> mDatas) {
        super(context, mDatas);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_doudou_work;
    }

    @Override
    protected void convert(ViewHolder helper, int position, MonthSumbitedItem item) {
        helper.setText(R.id.tv_submit_month, item.getMonth());
        MultiGridView gridView = helper.getView(R.id.gv_submited);
        final List<SubmitQuestion> teamplist = new ArrayList<SubmitQuestion>();
        teamplist.addAll(item.getQuestions());
        MonthSubmitedAdatper adapter;
        if (gridView.getAdapter() == null) {
            //            Log.i("sky", "getAdapter()==null");
            adapter = new MonthSubmitedAdatper(mContext, teamplist);
            gridView.setAdapter(adapter);
        } else {
            //            Log.i("sky", "getAdapter()!=null   questions.size()=" + questions.size());
            adapter = (MonthSubmitedAdatper) gridView.getAdapter();
            adapter.setData(teamplist);
            adapter.notifyDataSetChanged();
        }
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SubmitQuestion submitQuestion = teamplist.get(position);
                if (submitQuestion != null) {
                    Intent intent = new Intent(mContext, DDUploadActivity.class);
                    intent.putExtra(DDWorkListActivity.PARAM_DDWORKID, submitQuestion.getExamId());
                    intent.putExtra(DDWorkListActivity.PARAM_TITLE, submitQuestion.getExerName());
                    mContext.startActivity(intent);
                }
            }
        });
    }
}
